﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Mail;

/// <summary>
/// Summary description for SendEmail
/// </summary>
public class SendEmail
{

    public static bool EmailActivation(string emailTo, string content, string subject, string smtpServer, string password, string userName)
    {
        /*
        string smtpServer = Resources.global.SMTP;
        string userName = Resources.global.EmailAddress;
        string password = Resources.global.EmailPass;
         * */


        int cdoBasic = 1;
        int cdoSendUsingPort = 2;
        MailMessage message = new MailMessage();
        if (userName.Length > 0)
        {
            message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer);
            message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
            message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort);
            message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);
            message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
            message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
        }

        message.From = userName;
        message.To = emailTo;
        message.Subject = subject;
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.Body = content;
        message.BodyFormat = MailFormat.Html;
        SmtpMail.SmtpServer = smtpServer;
        SmtpMail.Send(message);

        return true;
    }
}
